package org.wjk.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.wjk.props.ThreadPoolProperties;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
@EnableAsync
@RequiredArgsConstructor
@Slf4j
public class ThreadPoolConfig
{
    private final ThreadPoolProperties props;

    @Bean("xfcimsThreadPool")
    public ThreadPoolExecutor threadPoolExecutor()
    {
        log.debug("ThreadPoolProperties is {}", props);
        return new ThreadPoolExecutor(props.getCoreSize(), props.getMaxSize(), props.getKeepAlive(), TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(props.getQueueCapacity()));
    }
}
